/**
 * Created by Administrator on 2017/10/17.
 */

function setwhitecolor(inputname) {
    $("#"+inputname).css("border-color", "#B8D3F1");
};

function erroProcess(){
       $('#img').attr('src','../../images/mmsPicBack.gif');
}
 /*字段设为空*/
function replacenull(str){
    var rtbstr = "";
    if(str=="null"|| str=="NULL" ||str==null){
        return rtbstr;
    }else{
        return str;
    }
}
/*判断浏览器是否为IE浏览器*/
function  isIE(){
    if(!! window.ActiveXObject || "ActiveXObject" in window)
        return true;
    else
        return false;
}
/**************/
function  getFileExt(str){
    var d=/\.[^\.]+$/.exec(str);
    return d;
}
/*  获取html的参数*/

function getUrlParam(name){
    nk="";
    var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
    var r=window.location.search.substr(1).match(reg);
    if(r!=null) return unescape(r[2]);else return nk;
}
/*
*
* 获取界面数据
* */

function getFormData(){
    var rtn = new Object();
    //input元素的值
    $("input[type=text]").each(function(){
        var element = $(this);
        if((element.attr("id")!=null) && (element.attr("id")!="")) {
            rtn[element.attr("id")] = element.val();
        }
    });
     $("input[type=hidden]").each(function(){
         var element=$(this);
         if((element.attr("id")!=null) && (element.attr("id")!="")) {
             rtn[element.attr("id")] = element.val();
         }
     });

     //input元素的值
    $("input[type=password]").each(function(){
        var element = $(this);
            if((element.attr("id")!=null)&&(element.attr("id")!="")){
                rtn[element.attr("id")]=element.val();
            }
    });

    //获取checkbox的值
    $("input[type=checkbox]").each(function(){
        var element = $(this);
        if(element.attr("checked")==true){
            if((element.attr("id")!=null)&&(element.attr("id")!="")){
                rtn[element.attr("id")]=element.val();
            }
        }
    });

    //获取radio的值
    $("input[type=radio]").each(function(){
        var element = $(this);
        if(element.attr("checked")==true){
            if((element.attr("name")!=null)&&(element.attr("name")!="")){
                rtn[element.attr("name")]=element.val();
            }
        }
    });

    //获取textarea的值
    $("txtarea").each(function() {
        var element = $(this);
        if ((element.attr("id") != null) && (element.attr("id") != "")) {
            rtn[element.attr("id")] = element.val()
        }
    });
    //获取select的值
    $("select").each(function(){
        var element = $(this);
        if ((element.attr("id") != null) && (element.attr("id") != "")) {
            rtn[element.attr("id")] = element.val()
        }
    });
    return  rtn;
}
/*
* 绑定数据
* */
function bindFormData(data){
    if((data== null) || (data="") || (data == undefined)){
        return ;
    }
    if(typeof(data)!= "object"){
        return ;
    }
    for(var key in data){
        var element = $("#"+key);
         if(element.length==0){
             continue;
         }
         if(element.attr("type")=="checkbox"){
             element.attr("checked",true);
             continue;
         }
         element.val(data[key]);
    }
}
/*
* 获取弹出对话框的参数
* */
  function getDialogArgs(){
      if(document.all){
          return window.dialogArguments;
      }else{
          return window.parent.dialogArguments;
      }
  }
  /*
  * 页面重置
  * */
function resetContent(id){
    var vaildForm=$('#'+id);
    vaildForm.find("input,select,textarea").val("");
    vaildForm.find('input[type="checkbox"]').each(function(){
        $(this).attr("checked,false");
    });
}
/**
 * 选中下拉列表
 * @param obj
 *         要绑定的Select对象
 * @param dataValue
 *         将要被绑定的值
 * @param flag
 *          选中标示，1根据值选中，0根据显示值选中
 * @return
 *
 * */
function  selectValue(obj,dataValue,flag) {
    var currentIndex = -1;
    if(flag=="1"){  //根据值选中
        for(var  i=0;i<obj.options.length;i++){
            var ops = obj.options[i];
            if(ops.value == dataValue){
                ops.setAttribute("selected","true");
                obj.selectedIndex = i;
                currentIndex = i;
                break;
            }
        }
    }else{
        for(var i =0;i<obj.options.length;i++){
            var ops= obj.options[i];
            if(ops.text == dataValue){
                ops.setAttribute("selected","true");
                obj.selelctedIndex = i;
                currentIndex = i;
                break;
            }
        }
    }
    return currentIndex;
}
/*
* 打开窗口
* */

function openWin(url,title){
    window.open(url,"maxwindow",'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,status=no');

}

/*
 * 清空select列表
 * @param  elementId
 * @return
 * */

function removeList(elementId){
      var list = document.getElementById(elementId);
      for(var i = list.options.length;i>=0;i--){
          list.remove(i);
      }
}
/**
 * 获取窗口高度
 *
 */
 function getHeight(){
     var winHeight= 500;
     //获取窗口高度
    if(window.innerHeight){
          winHeight=window.innerHeight;
    }else if((doucment.body)&&(document.body.clientHeight)) {
        winHeight = document.body.clientHeight;

    }//通过深入Document 内部对body进行检测，获取窗口大小
        if(document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){
            winHeight = document.documentElement.clientHeight;
        }
       return winHeight;
}

/*
获取窗口宽度
* */
function getWidth(){
     var   winWidth = 500;  //获取窗口宽度
     if(window.innerWidth){
         winWidth=window.innerWidth;
     }else if((document.body)&&(document.body.clientWidth)){
         winWidth=document.body.clientWidth;
     }//通过深入Document 内部对body进行检测，获取窗口大小
      if(document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight){
         winWidth=document.documentElement.clientWidth;
      }
      return winWidth;

}
//检验是否为0-9的数字
function is0To9(s){
    console.log(s);
    for(var i=0; i<s.length; i++) {
        var codeValue = s.charCodeAt(i);
        if(codeValue < 48 || codeValue > 57) return false;
    }
    return true;
}
//日期校验：YYYYMMDD
function isDate(s){
    var year=s.substring(0,4);
    var month=s.substring(4,6);
    var day=s.substring(6,8);
    if(!is0To9(year)||!is0To9(month)||!is0To9(day)) return false;
    //year
    var yearInt=parseInt(year);
    if(yearInt<1||yearInt>9999) return false;
    //month
    var monthInt = parseInt(month,10);
    if(monthInt<1||monthInt>12) return false;
    //day
    var dayInt=parseInt(day,10);
    var monthMax;
    if((yearInt%4==0&&yearInt%100!=0)||yearInt%400==0){
        monthMax=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
    }else{
        monthMax=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    }
    if(dayInt<1||dayInt>monthMax[monthInt-1]) return false;
    return true;
}
/*判断是否是数字*/

function isNum(s){
   return /^[0-9]+$/.test(s);
}
///<summary>获得字符串实际长度，中文2，英文1</summary>
///<param name="str">要获得长度的字符串</param>
function getstrlength(str) {
    if(str==null||str==""){
        return 0;
    }
    var realLength = 0, len = str.length, charCode = -1;
    for (var i = 0; i < len; i++) {
        charCode = str.charCodeAt(i);
        if (charCode >= 0 && charCode <= 128) realLength += 1;
        else realLength += 1;
    }
    return realLength;
};


//校验是否数字
function _isNum(s) {
    return /^[0-9]+$/.test(s);
}
//计算出合法身份证（17位或者18位）最后一位的校验位
function getCheckBit(idCode){
    var code=idCode.substring(0,17);
    var szVerCode="10X98765432";
    var iw=new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
    var bitValue = 0;
    for (var i=0; i<code.length; i++) {
        bitValue += code.charAt(i).valueOf() * iw[i];
    }
    bitValue = bitValue % 11;
    return szVerCode.charAt(bitValue);
}
//判断18位身份证
function is18IDCard(i){
    i=i.toUpperCase();
    if(i.length!=18) return false;
    if(!is0To9(i.substring(0,17))) return false;
    if(!isDate(i.substring(6,14))) return false;
    if(i.charAt(17)!=getCheckBit(i)) return false;
    return true;
}

//校验固话号码(适合固话，传真)
function isFTel(tel){
    /*if(/^\d{10}$/.test(s)||/^\d{11}$/.test(s)||/^\d{12}$/.test(s)||/^\d{7}$/.test(s)||/^\d{8}$/.test(s)){

     return true;
     }else{
     return false;
     }*/
    phone1 = /^0\d{2,3}-?\d{7,8}$/;
    phone2 = /^\d{7,8}$/;
    return phone1.test(tel)||phone2.test(tel);
}
//校验手机号码
function isMTel(s){
    if(!_isNum(s)){
        return false;
    }
    if(s.length!=11){
        return false;
    }
    //return /^1(3\d|(58|59|56|52|53|50|51|54|55|56|57|58|59|80|81|82|83|84|85|86|87|88|89|))\d{8}$/g.test(s);
    var regPartton=/1[3-8]+\d{9}/;
    return regPartton.test(s);
}
//校验电话号码
function isTel(s){
    return isFTel(s)||isMTel(s);
}
//验证合法身份证号
function  isCheckNum(idNo) {
    var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if (!regIdNo.test(idNo)) {
        alert('身份证号填写有误');
        return false;
    }
}















